/*
 * Copyright (c) 2009 Nathaniel Houghton <nathan@brainwerk.org>
 *                    Robert Kirchgessner <rkirchge@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for
 * any purpose with or without fee is hereby granted, provided that
 * the above copyright notice and this permission notice appear in all
 * copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 */

#ifndef UI_H
#define UI_H

#include <stdint.h>
#include <stdio.h>
#include "menu_res.h"

#define IGNITION_MSK 0x10

#define BTN_1 0x10
#define BTN_2 0x08
#define BTN_3 0x04
#define BTN_IGNITION 0x02
#define BTN_LCDPRESENT 0x01

#define LCD_LINE_LENGTH 20

void init_ui(void);

uint8_t btn_down(uint8_t);
#define lcd_update(A,B,C) printf("%s\n", C )
extern struct lcd lcd;

struct lcd {
	uint8_t initd;
	char line0[LCD_LINE_LENGTH+1];
	char line1[LCD_LINE_LENGTH+1];
};

struct menu_entry {
	uint8_t type; /*Type of menu entry*/
	uint8_t id;
	uint8_t left; /*Integer identifier to the next menu to display when the left button is pressed*/
	uint8_t right; /*Integer identifier to the next menu to display when the right button is pressed*/
	uint8_t enter; /*Integer identifier to next menu to display*/
	void (*fp)(void); /*Pointer to the function  to be run if enter pressed*/
};

struct static_menu_entry {
	uint8_t type; /*Type of menu entry*/
	uint8_t id;
	uint8_t left; /*Integer identifier to the next menu to display when the left button is pressed*/
	uint8_t right; /*Integer identifier to the next menu to display when the right button is pressed*/
	uint8_t enter; /*Integer identifier to next menu to display*/
	
	void (*fp)(void); /*Pointer to the function  to be run if enter pressed*/
	
	char disp[LCD_LINE_LENGTH+1]; /*Pointer to string to display*/
};

struct dynamic_menu_entry {
	uint8_t type; /*Type of menu entry*/
	uint8_t id;
	uint8_t left; /*Integer identifier to the next menu to display when the left button is pressed*/
	uint8_t right; /*Integer identifier to the next menu to display when the right button is pressed*/
	uint8_t enter; /*Integer identifier to next menu to display*/
	
	void (*fp)(void); /*Pointer to the function  to be run if enter pressed*/
	
	void (*disp)(void); /*Pointer to the function that will generate the message*/
};

struct menu {
	uint8_t current; /*current menu being displayed*/
	uint8_t length;
	
	struct menu_entry *menu_entries[MENU_ENTRY_COUNT]; /*All the menu entries in the menu*/	
};

#define MENU_ENTRY_STATIC 0x0
#define MENU_ENTRY_DYNAMIC 0x1



void init_menu( uint8_t );
void menu(void);


#endif
